package com.nut.spp.api.client;

import com.nut.spp.common.Holder;
import com.nut.spp.common.Result;
import com.nut.spp.entity.MemberAddress;
import com.nut.spp.service.MemberAddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@Slf4j
@RestController
@RequestMapping("/client/memberAddress")
public class MemberAddressController {

    @Autowired
    private MemberAddressService memberAddressService;

    @GetMapping("/list")
    public Result<List<MemberAddress>> list() {
        Long memberId = Holder.CLIENT_JWT_THREAD_LOCAL.get().getMemberId();
        return memberAddressService.list(memberId);
    }

    @GetMapping(value = "/{id}")
    public Result<MemberAddress> detail(@PathVariable Integer id) {
        return memberAddressService.getById(id);
    }

    @PostMapping
    public Result add(@RequestBody MemberAddress memberAddress) {
        return memberAddressService.add(memberAddress);
    }

    @PutMapping
    public Result update(@RequestBody MemberAddress memberAddress) {
        return memberAddressService.updateById(memberAddress);
    }

    @DeleteMapping
    public Result delete(@RequestBody Set<Integer> ids) {
        return memberAddressService.deleteByIds(ids);
    }

}